/**
 * 여행지 정보 삭제 script
 */
var xhr; 
	function createXMLHttpRequest(){
		if(window.ActiveXObject){// ms explorer일 경우 
			xhr=new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			xhr=new XMLHttpRequest();
		}
	}
	//1. 여행지 정보를 삭제한다.
	function startDeleteTravelInfo(){
		createXMLHttpRequest();		
		xhr.onreadystatechange=callbackDeleteTravelInfo; 
		xhr.open("POST","/wetogether/travelinfo_delete.do",true);		
		xhr.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded;charset=UTF-8");
		var place=checkedRadioButton(document.getElementsByName("place"));
		var flag=confirm(place+"을 정말 삭제하시겠습니까?");
		if(!flag){
			return;
		}
		xhr.send("mode=deleteTravelInfo&place="+place);
	}
	function callbackDeleteTravelInfo(){		
		if(xhr.readyState==4){		
			if(xhr.status==200){
				alert(xhr.responseText);
				clearDeleteTravelInfo();
			}
		}
	}
	//여행지 정보 삭제 후 창 지워주기
	function clearDeleteTravelInfo(){
		clearRadioButton(document.getElementsByName("locationid"));
		document.getElementById("placelist").innerHTML="";
		document.getElementById("pnumber").value="";
		document.getElementById("address").value="";
		document.getElementById("phomepage").value="http://";
		document.getElementById("information").value="";
		document.getElementById("traffic").value="";
		document.getElementById("trafficValue").innerHTML="";
		document.getElementById("map").value="";
		document.getElementById("mapValue").innerHTML="";
	}
	/////////////////////////////////////////////////////////
	
	// 2.여행지 이미지 삭제
	function startDeletePlaceImage(data){
		createXMLHttpRequest();		
		xhr.onreadystatechange=callbackDeletePlaceImage; 
		xhr.open("POST","/wetogether/travelinfo_delete.do",true);		
		xhr.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded;charset=UTF-8");	
		var place=checkedRadioButton(document.getElementsByName("place"));
		var gallery=data;
		var flag=confirm(place+"의 "+gallery+"을 정말 삭제하시겠습니까?");
		if(!flag){
			return;
		}
		xhr.send("mode=deletePlaceImage&place="+place+"&gallery="+gallery);
	}
	function callbackDeletePlaceImage(){		
		if(xhr.readyState==4){		
			if(xhr.status==200){
				alert(xhr.responseText);
				clearDeletePlaceImage();
			}
		}
	}
	// 이미지 값 삭제 후 창 지워주기
	function clearDeletePlaceImage(){
		clearRadioButton(document.getElementsByName("locationid"));
		document.getElementById("placelist").innerHTML="";
		document.getElementById("galleryValue").innerHTML="";
	}
	/////////////////////////////////////////////////

	// 3. 숙박 정보 삭제
	function startDeletePlaceVacancy(data){
		createXMLHttpRequest();		
		xhr.onreadystatechange=callbackDeletePlaceVacancy; 
		xhr.open("POST","/wetogether/travelinfo_delete.do",true);		
		xhr.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded;charset=UTF-8");	
	   	var stay=data;
		var place=checkedRadioButton(document.getElementsByName("place"));		
		var flag=confirm(place+"의 "+stay+"을 정말 삭제하시겠습니까?");
		if(!flag){
			return;
		}
		xhr.send("mode=deletePlaceVacancy&stay="+stay+"&place="+place);
	}
	function callbackDeletePlaceVacancy(){		
		if(xhr.readyState==4){		
			if(xhr.status==200){
				alert(xhr.responseText);
				clearDeletePlaceVacancy();
			}
		}
	}
	// 숙박정보 삭제 후 창 지워주기
	function clearDeletePlaceVacancy(){
		clearRadioButton(document.getElementsByName("locationid"));
		document.getElementById("placelist").innerHTML="";
		document.getElementById("vacancyValue").innerHTML="";
	}
	/////////////////////////////////////////////////////////
	 
	// 4. 맛집 정보 삭제
	function startDeletePlaceFr(data){
		createXMLHttpRequest();		
		xhr.onreadystatechange=callbackDeletePlaceFr; 
		xhr.open("POST","/wetogether/travelinfo_delete.do",true);		
		xhr.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded;charset=UTF-8");	
		var restaurant=data;
		var place=checkedRadioButton(document.getElementsByName("place"));
		var flag=confirm(place+"의 "+restaurant+"을 정말 삭제하시겠습니까?");
		if(!flag){
			return;
		}
		xhr.send("mode=deletePlaceFr&restaurant="+restaurant+"&place="+place);
	}
	function callbackDeletePlaceFr(){		
		if(xhr.readyState==4){		
			if(xhr.status==200){
				alert(xhr.responseText);
				clearDeletePlaceFr();
			}
		}
	}
	// 맛집정보 삭제 후 창 지워주기
	function clearDeletePlaceFr(){
		clearRadioButton(document.getElementsByName("locationid"));
		document.getElementById("placelist").innerHTML="";
		document.getElementById("frValue").innerHTML="";
	}
	//////////////////////////////////////////////////////
	
	// 5. 공지사항 삭제
	function startDeletePlaceNotice(){
		createXMLHttpRequest();		
		xhr.onreadystatechange=callbackDeletePlaceNotice; 
		xhr.open("POST","/wetogether/travelinfo_delete.do",true);		
		xhr.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded;charset=UTF-8");	
		var place=checkedRadioButton(document.getElementsByName("place"));
		var flag=confirm(place+"의 공지를 정말 삭제하시겠습니까?");
		if(!flag){
			return;
		}
		xhr.send("mode=deletePlaceNotice&place="+place);
	}
	function callbackDeletePlaceNotice(){		
		if(xhr.readyState==4){		
			if(xhr.status==200){
				alert(xhr.responseText);
				clearDeletePlaceNotice();
			}
		}
	}
	// 공지사항 삭제 후 창 지워주기
	function clearDeletePlaceNotice(){
		clearRadioButton(document.getElementsByName("locationid"));
		document.getElementById("placelist").innerHTML="";
		document.getElementById("notice").value="";
	}
	///////////////////////////////////////////////////
	
	// 6. 댓글 삭제  - 회원이 본인 글 삭제
	function startDeletePlaceComment(id,commend){
		createXMLHttpRequest();		
		xhr.onreadystatechange=callbackDeletePlaceComment; 
		xhr.open("POST","/wetogether/travelinfo_delete.do",true);		
		xhr.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded;charset=UTF-8");	
		var place=document.getElementById("place").value;
		var memberid=id;
		var recommend=commend;
		var flag=confirm(place+"의 "+id+"님 댓글을 정말 삭제하시겠습니까?");
		if(!flag){
			return;
		}
		xhr.send("mode=deletePlaceComment&place="+place+"&memberid="+memberid
				+"&recommend="+recommend);
	}
	function callbackDeletePlaceComment(){		
		if(xhr.readyState==4){		
			if(xhr.status==200){
				alert(xhr.responseText);
				clearDeletePlaceComment();
				var locationId=document.getElementById("locationId").value;
				var place=document.getElementById("place").value;
				location.href="/wetogether/travelinfo_output.do?mode=outputTravelInfo&place="
					+place+"&locationId="+locationId;
			}
		}
	}
	// 댓글 삭제 후 창 지워주기
	function clearDeletePlaceComment(){
		document.getElementById("commentValue").innerHTML="";
	}
	///////////////////////////////////////////////////
	
	// 6. 댓글 삭제  - 관리자가 회원 댓글 삭제
	function startDeletePlaceCommentValue(id,commend){
		createXMLHttpRequest();		
		xhr.onreadystatechange=callbackDeletePlaceCommentValue; 
		xhr.open("POST","/wetogether/travelinfo_delete.do",true);		
		xhr.setRequestHeader("Content-type",
				"application/x-www-form-urlencoded;charset=UTF-8");	
		var place=checkedRadioButton(document.getElementsByName("place"));
		var memberid=id;
		var recommend=commend;
		var flag=confirm(place+"의 "+id+"님 댓글을 정말 삭제하시겠습니까?");
		if(!flag){
			return;
		}
		xhr.send("mode=deletePlaceComment&place="+place+"&memberid="+memberid
				+"&recommend="+recommend);
	}
	function callbackDeletePlaceCommentValue(){		
		if(xhr.readyState==4){		
			if(xhr.status==200){
				alert(xhr.responseText);
				clearDeletePlaceCommentValue();
			}
		}
	}
	// 댓글 삭제 후 창 지워주기
	function clearDeletePlaceCommentValue(){
		clearRadioButton(document.getElementsByName("locationid"));
		document.getElementById("placelist").innerHTML="";
		document.getElementById("memberValue").innerHTML="";
	}
	///////////////////////////////////////////////////
	
	// 선택된 라디오버튼 값을 리턴
	function checkedRadioButton(data){
		var dataValue;
		for(i=0; i<data.length; i++){
			if(data[i].checked){
				dataValue=data[i].value;
				break;
			}
		}
		return dataValue;
	}
	// 라디오버튼 선택 해제
	function clearRadioButton(data){
		for(i=0; i<data.length; i++){
			data[i].checked=false;
		}
	}
	// 리스트의 값 만큼 라디오버튼 생성
	function createRadioButton(obj){
		var str="";
		for(i=0; i<obj.length; i++){
			str+="<input type='radio' name='place' value="+obj[i]+" onchange='selectPlace()'></input>"+obj[i];
		}
		return str;
	}
	///////////////////////////////////////////////////
	
	function imgChange(data){
		var str="/wetogether_test/travelinfo/img/"+data;
		document.getElementById("imgchange").innerHTML="<img src="+str+"></img>";
	}